// lib/authapi.ts
// 认证相关的 API 接口

import { apiClient, API_ENDPOINTS, TokenManager } from '@/lib/api-client'

// 认证相关 API
export const authAPI = {
  // 检查用户类型
  checkUserType: async (email: string) => {
    return apiClient.post(API_ENDPOINTS.checkUserType, { email }, false)
  },

  // 登录
  login: async (credentials: { 
    email: string; 
    password: string;
    user_type: string;
  }) => {
    return apiClient.post(API_ENDPOINTS.login, credentials, false)
  },

  // 登出
  logout: async (refreshToken: string) => {
    return apiClient.post(API_ENDPOINTS.logout, { refresh: refreshToken })
  },

  // 获取用户信息
  getProfile: async () => {
    return apiClient.get(API_ENDPOINTS.profile)
  },

  // 更新用户信息
  updateProfile: async (userData: Partial<{
    username: string
    email: string
    full_name: string
    phone: string
    institution: string
    laboratory: string
  }>) => {
    return apiClient.patch(API_ENDPOINTS.updateProfile, userData)
  },

  // 修改密码
  changePassword: async (passwordData: {
    old_password: string
    new_password: string
    new_password_confirm: string
  }) => {
    return apiClient.post(API_ENDPOINTS.changePassword, passwordData)
  },
}

// 机构和实验室相关 API
export const institutionAPI = {
  // 获取机构列表
  getInstitutions: async () => {
    return apiClient.get(API_ENDPOINTS.institutions, false)
  },

  // 获取实验室列表
  getLaboratories: async (institutionCode?: string) => {
    const params = institutionCode ? `?institution=${institutionCode}` : ''
    return apiClient.get(`${API_ENDPOINTS.laboratories}${params}`, false)
  },
}